﻿using System.Diagnostics;

using Game.Map;
using Game.Map.Extensions;
using Game.Objects;

namespace SL
{
    public static class BuildingPropertyPrinter
    {

        static public string GetInfo(IGameMapView map)
        {
            if (map.SelectedX().Selected == null)
            {
                return "";
            }

            var selected = map.SelectedX().Selected;
            Debug.Assert(selected != null, "view != null");
            var view = map.ViewFields[selected.Point];

            if (view.IsVisible == false)
            {
                return "";
            }

            string s = null;

            var v = map.SelectedX().Selected.VehicleX().Vehicle;
            if (v != null)
            {
                s = "";
                s += v.VehicleType.Name + "\r\n\r\n";
                s += "Movement: " + v.Movement.Value + "\r\n";
                s += "Experience: " + v.Experience + "\r\n";
                s += "Armor: " + v.Armor + "\r\n";
                s += "Damage: " + v.Damage + "\r\n";
                s += "\r\n";

                s += "Energy: " + v.Tank.Energy.Value + "\r\n";
                s += "Fuel: " + v.Tank.Fuel.Value + "\r\n";
                s += "Material: " + v.Tank.Material.Value + "\r\n";
            }
            else
            {
                var obj = map.SelectedX().Selected.ObjectX().GameObject;
                if (obj != null)
                {
                    s = "";
                    var building = obj.Building as GameBuilding;
                    if (building != null)
                    {
                        s += building.BuildingType.Name + "\r\n\r\n";

                        s += "Energy: " + building.Tank.Energy.Value + "\r\n";
                        s += "Fuel: " + building.Tank.Fuel.Value + "\r\n";
                        s += "Material: " + building.Tank.Material.Value + "\r\n";
                    }
                    else
                    {
                        s += obj.MapItemType.Name + "\r\n\r\n";
                        s += "TerrainCost: " + 
                            map.SelectedX().Selected.TerrianX().TerrainCost + 
                            "\r\n";
                    }
                }
                else
                {
                    s += map.SelectedX().Selected.TerrianX().TerrainType.Name + "\r\n\r\n";
                    s += "TerrainCost: " +
                        map.SelectedX().Selected.TerrianX().TerrainCost + 
                        "\r\n";
                }
            }

            return s;
        }
    }
}
